<?php
// 如果是post提交，就从数据库获取用户数据
if($_SERVER['REQUEST_METHOD']=="POST") {
	
	// 获取用户账号密码
	$username = $_POST['username'];
	$password = $_POST['password'];
	
	include_once("pdo.php");
	// $sql = "select * from users where username='".$username."' and password='".$password."'";
	$sql = "select * from users where username=:username and password=:password";
	
	// 预处理sql语句
	$stmt = $pdo->prepare($sql);
	
	// 绑定参数
	$stmt->bindParam(":username", $username);
	$stmt->bindParam(":password", $password);
	
	// 执行sql语句
	$stmt->execute();
	
	// 获取一行数据
	$row = $stmt->fetch();
	
	// 如果找到，返回登陆成功
	if($row){
		header("location: ./admin/list.php");
		exit();
	} else {// 否则返回登录失败
		die("登陆失败");
	}
	die("post类型的请求");
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title></title>
	<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
	
	<!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
	
	<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
	<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
	<style>
		html{height:100%;}
		body{
			height:100%; 
			background: url(img/01.jpeg) no-repeat; 
			background-size: cover; 
			overflow: hidden;
		}
		.login-box{
			padding:50px;
			position: relative;
		}
		
		/* 制作一个和父元素一样大小的div 用于设置半透明 */
		.login-box>.into{
			position: absolute;  /*绝对定位，由于父元素login-box设置了 position: relative; 属性，所以会相对父元素来定位*/
			width:100%;
			height:100%;
			background:#fff;
			z-index: -1;
			top:-5px;
			left:-5px;
			opacity: .5;  /* 透明度50% */
			border-radius: 20px;  /*圆角*/
		}
	</style>
</head>
<body>
	<div class="row" style="margin-top:200px;">
		<form action="" method="post">
			<div style="font-size: 30px; font-weight: 900; text-align: center; margin-bottom: 30px;">后台登录</div>
			<div class="col-md-4 col-md-offset-4 login-box">
				<div class="into"></div>
				<div class="input-group input-group-lg" style="margin-bottom: 30px;">
				  <span class="input-group-addon" id="sizing-addon1">账号</span>
				  <input type="text" name="username" class="form-control" placeholder="用户名">
				</div>
				
				<div class="input-group input-group-lg" style="margin-bottom: 30px;">
				  <span class="input-group-addon" id="sizing-addon1">密码</span>
				  <input type="text" name="password" class="form-control" placeholder="密码">
				</div>
				
				<div>
				  <button class="form-control btn btn-primary" >登录</button>
				</div>
			</div>
		</form>
	</div>
	
</body>
</html>